forward reference not resolved

I have two functions which need to call each other.
The function first in the code is not able to call the second.
Can functions be forward declared? If so what is the syntax?
SystemAdmin - Thu Dec 23 07:53:35 EST 2010

Re: forward reference not resolved
OurGuest - Thu Dec 23 16:07:21 EST 2010

Here is a demo of what I think you are asking about:
 

string test1(string, int)
string test2(string, int)
 
string s = test1("Input", 3)
 
print "\n" s
s = test2("TEST2", 2)
 
print "\n" s
 
string test1(string sInput, int iInput)
{ string s=test2("A",1) 
  print "Printed in test1: " s  "  " sInput ",  " iInput  ""
  return "Returned from test1: " s
}
 
string test2(string sInput, int iInput)
{ return "Returned from test2: " sInput "-" iInput ""
}

Re: forward reference not resolved
SystemAdmin - Tue Jan 04 07:08:04 EST 2011

OurGuest - Thu Dec 23 16:07:21 EST 2010

Here is a demo of what I think you are asking about:
 

string test1(string, int)
string test2(string, int)
 
string s = test1("Input", 3)
 
print "\n" s
s = test2("TEST2", 2)
 
print "\n" s
 
string test1(string sInput, int iInput)
{ string s=test2("A",1) 
  print "Printed in test1: " s  "  " sInput ",  " iInput  ""
  return "Returned from test1: " s
}
 
string test2(string sInput, int iInput)
{ return "Returned from test2: " sInput "-" iInput ""
}

Yeah that's it. Thanks.
I was trying to do it with Arguments passed by Ref with the ampersand which is why I was having trouble.

Re: forward reference not resolved
Zetareticuli - Wed Jan 05 13:18:26 EST 2011

I believe this is called "Forward Declaration" or "Forward Declare" as well. I'll respond with this phrase so that if anyone else is searching the forums for how to do this, they can be directed to this thread.

Re: forward reference not resolved
SystemAdmin - Thu Jan 06 06:18:10 EST 2011

Zetareticuli - Wed Jan 05 13:18:26 EST 2011
I believe this is called "Forward Declaration" or "Forward Declare" as well. I'll respond with this phrase so that if anyone else is searching the forums for how to do this, they can be directed to this thread.

This is how to do it with ByRef arguments:
void Function2(string&, int&, int)

void Function1(string &Message, int &Count, int Max)
{
if(Count>=Max){return}

Message = Message "~"
Count += 1
Function2(Message , Count, Max)
}

void Function2(string &Message, int &Count, int Max)
{
if(Count>=Max){return}

Message = Message "#"
Count += 1
Function1(Message , Count, Max)
}

string Message = ""
int Count = 0
Function1(Message, Count, 5)
print Count Message

Re: forward reference not resolved
strathglass - Wed Apr 11 08:11:24 EDT 2018

Old thread, but I was wondering if there was a way to forward declare a function like "Shell createShell()" from Mathias's github Parallel's library?

The above approach does not work presumably because of the "custom type" this function has.

Re: forward reference not resolved
Mathias Mamsch - Wed Apr 11 17:21:05 EDT 2018

strathglass - Wed Apr 11 08:11:24 EDT 2018

Old thread, but I was wondering if there was a way to forward declare a function like "Shell createShell()" from Mathias's github Parallel's library?

The above approach does not work presumably because of the "custom type" this function has.

Wild guess - should should be fine with simply declaring the Shell struct twice (before the forward declaration)? The need for forward declaration is usually a sign of a bad include layout. You might be better of with fixing your library structure in the long run. Regards, Mathias